<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/common.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mask.css">
    <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    <script src="${pageContext.request.contextPath}/js/my.js"></script>
    <%--弹框插件--%>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/xcConfirm/css/xcConfirm.css"/>
    <script src="${pageContext.request.contextPath}/xcConfirm/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>

    <style type="text/css">
        .body-content{
            width: 60%;
            margin: 20px 0px;
            box-shadow: 3px -3px 3px #dedede, -3px 3px 3px #dedede, -3px -3px 3px #dedede;
            background-color: #f7f7f7;
        }
        .option{
            padding: 10px 40px;
        }
        .title{
            color: #333;
            width: 130px;
        }
        .w10{
            width: 100px;
            float:left;
        }
    </style>
</head>
<body>

<div class="panel admin-panel">
    <div class="panel-head" id="add">
        <strong>
            <span class="icon-pencil-square-o"></span> 制作印章
        </strong>
    </div>
    <div class="padding border-bottom">
        <ul class="search" style="padding-left:10px;">
            <li><a class="button border-main icon-plus-square-o" href="javaScript:window.location.href = document.referrer;"> 返回</a></li>
        </ul>
    </div>
    <div class="ub">
        <div class="body-content  f-s-14 c-6">
            <div class="ub option">
                <div class="title f-w">输入密码：</div>
                <div class="ub-f1" >
                    <input type="password" id="psw" name="psw" value="" />
                </div>
            </div>
            <div class="ub option">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button type="button" class="button bg-main icon-check-square-o" onclick="ImportToUK()">下载</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    let serverOK = false;
    function sealInfoHandler(sRet){
        serverOK = true;
        if(sRet.status == "0"){
            // 失败,提示错误信息
            alert(sRet.errmsg);
        }else{
            if( sRet.COM == "1" ) {
                //这里返回公钥数据
                $("#ukinfo").val(sRet.PUK);
            }else{
                alert("COM:" + sRet.COM);
            }
        }
    }

    function randomFrom(lowerValue,upperValue) {
        let d = new Date()
        return d.getTime();
    }

    function clientStatus() {
        if(serverOK == false){
            alert("请先运行客户端程序");
        }
    }

    function myAjax(src)
    {
        serverOK = false;
        ajaxStatus = false;
        var script = document.createElement('script');
        script.setAttribute("type","text/javascript");
        var url = src + "?RN=" + randomFrom(1,1000);
        script.src = url;
        var node = document.body.appendChild(script);
        setTimeout("clientStatus()",30000);
    }

    function GenPublicKey(){
        var url = "http://127.0.0.1:9970/ESSMakeSeal/GenPublicKey?PWD=" + $("#psw").val() + "&RN=" + randomFrom(1,1000);
        myAjax(url);
    }
    function ImportToUK(){
        alert("通知UK执行写入动作");
        var url = "http://127.0.0.1:9970/ESSMakeSeal/ImportToUK?PWD=" + $("#psw").val() + "&RN=" + randomFrom(1,1000);
        myAjax(url);
        sleep(4000);
        window.location.href = document.referrer;
    }
    function sleep(delay) {
        var start = (new Date()).getTime();
        while ((new Date()).getTime() - start < delay) {
            continue;
        }
    }
</script>

</body></html>